import moment from 'moment'

// 日期格式化
export function parseDate(time) {
    return moment(time).format("YYYY-MM-DD");
}

export function parseDateTime(time) {
    return moment(time).format("YYYY-MM-DD HH:mm:ss");
}

export function parseDatePattern(time, pattern) {
    return moment(time).format(pattern);
}

// 回显数据字典
export function selectDictLabel(datas, value) {
    let actions = [];
    Object.keys(datas).map((key) => {
        if (datas[key].value === ('' + value)) {
            actions.push(datas[key].name);
            return false;
        }
    });
    return actions.join('');
}

export function selectDataField(datas, value) {
    let actions = [];
    Object.keys(datas).map((key) => {
        if (datas[key].id == value) {
            actions.push(datas[key].name);
            return false;
        }
    });
    return actions.join('');
}

export function selectDataFields(datas, value, split) {
    let valueArr = value.split(split);
    let actions = [];
    Object.keys(datas).map((key) => {
        let v;
        for (v in valueArr) {
            if (datas[key].id == valueArr[v]) {
                actions.push(datas[key].name);
            }
        }
    });
    return actions.join(',');
}